package vista;

import java.awt.EventQueue;

public class Layout extends Thread{

	JFrame frame;

	/**
	 * Launch the application.
	 */
	/*public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Layout window = new Layout();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}*/

	/**
	 * Create the application.
	 */
	public Layout() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 450, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		Button button = new Button("Atende o primeiro");
		frame.getContentPane().add(button, BorderLayout.NORTH);
		
		final TextArea TXTclientes = new TextArea();
		frame.getContentPane().add( TXTclientes, BorderLayout.SOUTH);
		
		
		
		
		
		button.addActionListener(new ActionListener() {
			@SuppressWarnings("deprecation")
			@Override
			public void actionPerformed(ActionEvent arg0) {
				Simulador.getInstance().Encerra();
				Simulador.getInstance().stop();
				
				FilaCliente filaC = GerenciadorFila.getInstance().getFilaCliente();
				ArrayList<Cliente> fila = filaC.getFila();
				
				if (!fila.isEmpty()) {
					TXTclientes.setText(null);
					for(Cliente c : fila){
						TXTclientes.append(c.getId()+"\n");
					}
					filaC.poll( new Random().nextInt(6));
					TXTclientes.append("O primeiro da fila e o cliente de ID=" +fila.get(0).getId()+"\n");
					
				}
				else TXTclientes.setText("Fila vazia\n");
				

				//GerenciadorFila.getInstance().getFilaCliente().Imprimir();
				
				
			}
		});
	}

}
